package com.biye.auth.controller;

import com.alipay.api.AlipayApiException;
import com.base.common.alipay.util.AlipayUtil;
import com.biye.auth.service.MoneyCallBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@Controller
public class MoneyCallBackController {

    @Autowired
    private MoneyCallBackService moneyCallBackService;

    @ResponseBody
    @RequestMapping(value = "/alipay/notifyUU", method = RequestMethod.POST )
    public void refund(HttpServletRequest request) throws UnsupportedEncodingException, AlipayApiException {
        Map<String, String> verify_result = AlipayUtil.verify(request);
        if (verify_result != null) {
//            do sth use params
//            System.out.println(verify_result.toString());
            moneyCallBackService.updateStuAccountBalance(verify_result);
        }
    }

}
